package com.afdor.rws.event.channel.aliyun.mq;

import com.afdor.rws.event.channel.client.producer.AbstractEventProducer;
import com.afdor.rws.event.config.EventConfigUtils;
import com.aliyun.mns.client.CloudAccount;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

/**
 * 基于阿里云MQ的生产者抽象实现
 *
 * @author 悭梵
 * @date Created in 2018-08-16 15:33
 */
@ToString
@EqualsAndHashCode
public abstract class AbstractAliyunEventProducer extends AbstractEventProducer {

    @Getter
    private CloudAccount cloudAccount;

    @Override
    public AbstractAliyunEventProducer init() {
        super.init();
        if (cloudAccount == null) {
            cloudAccount = new CloudAccount(EventConfigUtils.getProperty(AliyunMQChannelProvider.ALIYUN_MQ_SECRET_ID), EventConfigUtils.getProperty(AliyunMQChannelProvider.ALIYUN_MQ_SECRET_KEY), EventConfigUtils.getProperty(AliyunMQChannelProvider.ALIYUN_MQ_ENDPOINT));
        }
        return this;
    }

    @Override
    public void destroy() {
        cloudAccount = null;
        super.destroy();
    }
}
